package mapred;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.lib.IdentityMapper;

@SuppressWarnings("unchecked")
public class MapConfig {

	private Class<? extends Mapper> mapperClass;

	private Class<? extends Writable> outputKeyClass;

	private Class<? extends Writable> outputValueClass;

	private int numMapTasks;

	private boolean compressMapOutput;

	private Class<? extends CompressionCodec> outputCompressorClass;

	private MapConfig(Class<? extends Mapper> mapperClass, int numMapTasks,
			Class<? extends Writable> outputKeyClass,
			Class<? extends Writable> outputValueClass,
			Class<? extends CompressionCodec> outputCompressorClass) {
		if (mapperClass == null) {
			this.mapperClass = IdentityMapper.class;
		} else {
			this.mapperClass = mapperClass;
		}
		this.numMapTasks = numMapTasks;
		this.outputKeyClass = outputKeyClass;
		this.outputValueClass = outputValueClass;
		if (outputCompressorClass == null) {
			this.compressMapOutput = false;
		} else {
			this.compressMapOutput = true;
			this.outputCompressorClass = outputCompressorClass;
		}
	}

	public static MapConfig newInstance(Class<? extends Mapper> mapperClass,
			int numMapTasks, Class<? extends Writable> outputKeyClass,
			Class<? extends Writable> outputValueClass,
			Class<? extends CompressionCodec> outputCompressorClass) {
		return new MapConfig(mapperClass, numMapTasks, outputKeyClass,
				outputValueClass, outputCompressorClass);
	}

	public Class<? extends Mapper> getMapperClass() {
		return mapperClass;
	}

	public Class<? extends Writable> getOutputKeyClass() {
		return outputKeyClass;
	}

	public Class<? extends Writable> getOutputValueClass() {
		return outputValueClass;
	}

	public int getNumMapTasks() {
		return numMapTasks;
	}

	public boolean isCompressMapOutput() {
		return compressMapOutput;
	}

	public Class<? extends CompressionCodec> getOutputCompressorClass() {
		return outputCompressorClass;
	}

}
